<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <title>添加单元</title>
    <link rel="stylesheet" href="../layui/css/layui.css"/>
    <link rel="stylesheet" href="../css/admin.css"/>
    <style>
      .layui-form{
      width: 350px;
      height:80px;
      margin:0 auto;
      }
      .add-name th{
        width:100px;
        height:40px;
        font-size:14px;
        padding: 0;
        vertical-align: middle;
      }
      .add-name input{
        outline:none;
        width:160px;
        height: 28px;
        border:1px solid #E5BA70;
        border-radius:5px;
      }
      .tianjia-checkBox th{
        width:100px;
        height:40px;
        font-size:14px;
        padding: 0;
        vertical-align: middle;
      }
      tr.tianjia-checkBox td input{
        display: inline-block;
      }
      .layui-form .layui-table{
        margin-top:50px;
        margin:0 auto;
      }
      .layui-input-block  span{
      font-size: 14px;
      }
     .layui-input-block th{
       font-size: 14px;
      }
     #btn-c,#btn-s{
      border:0;
      margin-top: 3px;
      width: 100px;
      height: 28px;
      border-radius:5px;
      background-color: #D8D8D8;
     }
     #btn-c{
       margin-left:70px;
     }
     #btn-s:hover,#btn-c:hover{
     color:#fff;
     background-color:#EF7632;
     }
     #btn-s{
        margin-left:15px;
     }
     .layui-layer .layui-layer-title{
      background-color: #fff;
     }
     .more{
      margin-left:60px;
     }
    </style>
</head>
<body>
     <span class="more">温馨提示：(请确认已经选择小区)</span>
     <form class="layui-form" action="">
            <table class="layui-table layui-table-add" lay-skin="nob">
              <tbody>

          <tr class="add-name">
              <th>幢&nbsp;名称</th>
              <td><input type="text" id="zhuang" value=""  placeholder="&emsp;如：1幢" onfocus="this.style.color='#777';
       this.value='';"  onblur="this.style.color='#777';  this.value=this.value"  /></td>
            </tr>
                <tr class="add-name">
                  <th>单元名称</th>
                  <td><input type="text" id="danyuan" value="" placeholder="&emsp;如：1单元" onfocus="this.style.color='#777';
       this.value='';"  onblur="this.style.color='#777';  this.value=this.value"/></td>
                </tr>
              </tbody>
            </table>
          <input type="button" id="btn-c" value="取消">
          <input type="button" id="btn-s" value="保存">
        </form>
    <script type="text/javascript" src="../layui/layui.js"></script>
    <script>
        layui.use(['jquery','form','upload','layer'], function(){
            var $ = layui.jquery,layer = layui.layer;

      $("#btn-s").off("click").on("click",function(){
        //var danyuan_id =
        var zhuang_name = $("#zhuang").val();
        var danyuan_name = $("#danyuan").val();

        var building_id =localStorage.getItem("buildingId");
            console.log(building_id);

       console.log(zhuang_name);
       console.log(danyuan_name);
       console.log(building_id);

       if(zhuang_name &&danyuan_name){
         $.ajax({
           url: '../../elevator_manage/addZhuangDanyuan',
           type: 'POST',
           dataType: "json",
           data: {
             zhuang_name:zhuang_name,
             danyuan_name:danyuan_name,
             building_id:building_id
          }
        ,
           success:function(response){
             console.log(response);
               alert("添加成功");
               window.parent.location.reload();
               var index=parent.layer.getFrameIndex(window.name);
               parent.layer.close(index);
             if(response.resultCode == '200'){

            }
          },
           error:function(response){
              console.log(response);
               alert("添加失败");
               window.parent.location.reload();
               var index=parent.layer.getFrameIndex(window.name);
               parent.layer.close(index);
              if(response.resultCode=='001'){
                console.log("param is not found")
                }
                }
        });
      }
    })
   $("#btn-c").click(function(){
       window.parent.location.reload();
       var index=parent.layer.getFrameIndex(window.name);
      parent.layer.close(index);
     })
        });
    </script>
</body>
</html>
